import { createStore } from 'vuex'

import createPersistedState from 'vuex-persistedstate'

export interface State {
  count: number
}

const store = createStore<State>({
  state: {
    count: 0
  },
  getters: {
    count: (state) => state.count
  },
  mutations: {
    increment(state) {
      state.count++
    },
    decrement(state) {
      state.count--
    }
  },
  actions: {
    increment(context) {
      context.commit('increment')
    },
    decrement(context) {
      context.commit('decrement')
    }
  },
  plugins: [
    createPersistedState({
      storage: window.localStorage,
      reducer(val) {
        return {
          val
        }
      }
    })
  ]
})
export default store
